<?php

/**
 * PageController is the default controller for this application
 */
class PageController extends BrowseControllerBase {
	/**
	 * Constructor of index
	 */
	public function __construct() {
		parent::__construct ();
	}
	
	/**
	 * The "index" action is the default action for all controllers -- the
	 * landing page of the site.
	 *
	 * @return void
	 *
	 */
	public function indexAction() {
		$id = $this->getQuery ( 'id' );
		$id = intval ( $id );
		
		$pageEntity = $this->pageDataService->getById ( $id );
		if (empty ( $pageEntity )) {
			// Go on to login page
			$url = Zend_Registry::get ( 'config' )->APPLICATION_URL;
			CommonUtils::redirect ( $url );
			return - 1;
		}
		$pageEntity->content = htmlspecialchars_decode ( $pageEntity->content, ENT_QUOTES );
		
		$this->smarty->assign ( 'pageEntity', $pageEntity );
		$this->smarty->assign ( 'SMARTY_CONTENT_PATH', 'Browse/Page/index.tpl' );
		$this->smarty->display ( APPLICATION_PATH . '/Layouts/Browse/MainLayout.tpl' );
	}
}
